<template>
  <div class="app-container">
    <div class="customContainer towTabel">
      <!-- 列表 -->
      <div style="padding-bottom:10px;height:42px;display:flex;justify-content:space-between;align-items:center">
        <div>
          <span>采购单号：</span>
          <span>{{order_id}}</span>
        </div>
        <el-button v-show="isShowAddGift" type="primary" size="small" class="pull-right" @click="addClick()">添加礼品</el-button>
      </div>
      <el-table highlight-current-row :data="list" v-loading.body="listLoading" border size="small">
        <el-table-column align="center" label="序号" width="50">
          <template slot-scope="scope">
            <span class="indexColor">{{scope.$index+1+(currentPage-1)*20}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="图片" prop="creat_time" width="80">
          <template slot-scope="scope">
            <div v-viewer="options" class="images fit">
              <img :src="scope.row.thumb" :data-source="scope.row.img" class="image" :key="scope.row.thumb" />
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="名称" prop="gift_name">
        </el-table-column>
        <el-table-column align="center" label="礼品编号" prop="gift_id"></el-table-column>
        <el-table-column align="center" label="下单进货价(元)" prop="money_sell"></el-table-column>
        <el-table-column align="center" label="当前进货价(元)" prop="now_money_sell"></el-table-column>
        <el-table-column align="center" label="剩余库存(个)" v-if="type==2" key="now_num" prop="now_num">
          <template slot-scope="scope">
            {{scope.row.now_num-scope.row.now_order_num+(scope.row.before_num?scope.row.before_num*1:0)}}
          </template>
        </el-table-column>
        <el-table-column align="center" label="箱规 (个/箱)" prop="box_num" key="box_num"></el-table-column>
        <el-table-column align="center" label="下单数量(个)" prop="order_num"></el-table-column>
        <el-table-column align="center" label="当前数量(个)" prop="now_order_num">
          <template slot-scope="scope">
            <el-input v-if="scope.row.isSave" :maxlength="6" @blur="inputBurl(scope.row)" v-model="scope.row.now_order_num" placeholder="请输入数量"></el-input>
            <span v-else>{{scope.row.now_order_num}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="下单金额(元)" prop="old_total">
          <template slot-scope="scope">{{scope.row.money_sell*scope.row.order_num|keepTwoNum}}</template>
        </el-table-column>
        <el-table-column align="center" label="当前金额(元)" prop="total">
          <template slot-scope="scope">{{scope.row.now_money_sell*scope.row.now_order_num|keepTwoNum}}</template>
        </el-table-column>
        <el-table-column align="center" label="使用区域" prop="area">
          <template slot-scope="scope">
            <el-button v-if="scope.row.isSave" type="text" @click="showAreaDiag(scope.row)">{{scope.row.area_type|useAreaType}}</el-button>
            <span v-else>{{scope.row.area_type|useAreaType}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="备注" key="remark">
          <template slot-scope="scope">
            <el-input v-if="scope.row.isSave" :maxlength="24" v-model="scope.row.remark"></el-input>
            <span v-else>{{scope.row.remark}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" v-if="isShowAddGift" key="setGift">
          <template slot-scope="scope">
            <el-button type="danger" size="mini" @click="handleClick(scope.$index)">移除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 订货指标 -->
      <el-table :data="top_list" highlight-current-row v-loading.body="listLoading" border size="small" style="margin-top:10px">
        <el-table-column label="门店订货指标" width="150" align="center" prop="name"></el-table-column>
        <el-table-column label="礼品机区域" align="center">
          <el-table-column label="金额" align="center">
            <template slot-scope="scope">
              <el-button @click="getRegion()" type="text" size="mini" :class="top_list[1].a1*1>top_list[0].a1*1.1?'danger':''">{{scope.row.a1}}</el-button>
            </template>
          </el-table-column>
          <el-table-column label="数量" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.a2}}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="礼品柜区域" align="center">
          <el-table-column label="金额" align="center">
            <template slot-scope="scope">
              <el-button @click="getRegion()" type="text" size="mini" :class="top_list[1].a3*1>top_list[0].a3*1.1?'danger':''">{{scope.row.a3}}</el-button>
            </template>
          </el-table-column>
          <el-table-column label="数量" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.a4}}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="摊位机区域" align="center">
          <el-table-column label="金额" align="center">
            <template slot-scope="scope">
              <el-button @click="getRegion()" type="text" size="mini" :class="top_list[1].a5*1>top_list[0].a5*1.1?'danger':''">{{scope.row.a5}}</el-button>
            </template>
          </el-table-column>
          <el-table-column label="数量" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.a6}}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="企划区域" align="center">
          <el-table-column label="金额" align="center">
            <template slot-scope="scope">
              <el-button @click="getRegion()" type="text" size="mini" :class="top_list[1].a7*1>top_list[0].a7*1.1?'danger':''">{{scope.row.a7}}</el-button>
            </template>
          </el-table-column>
          <el-table-column label="数量" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.a8}}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="其他区域" align="center">
          <el-table-column label="金额" align="center">
            <template slot-scope="scope">
              <el-button @click="getRegion()" type="text" size="mini" :class="top_list[1].a9*1>top_list[0].a9*1.1?'danger':''">{{scope.row.a9}}</el-button>
            </template>
          </el-table-column>
          <el-table-column label="数量" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.a10}}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="合计" align="center">
          <el-table-column label="金额" align="center">
            <template slot-scope="scope">
              <span :class="top_list[1].a11*1>top_list[0].a11*1.1?'danger':''">{{scope.row.a11}}</span>
            </template>
          </el-table-column>
          <el-table-column label="数量" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.a12}}</span>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
    </div>
    <!-- 弹框 -->
    <el-dialog width="400px" title="礼品详情" :visible.sync="myinfoDialog">
      <div class="info_dialog">
        <div>名称：{{gift_info.gift_name}}</div>
        <div>礼品编号：{{gift_info.id}}</div>
        <div>神采编号：{{gift_info.no_obsolete}}</div>
        <div>国标码：{{gift_info.gb_code}}</div>
        <div>一级类别：{{gift_info.one_type}}</div>
        <div>二级类别：{{gift_info.tow_type}}</div>
        <div>三级类别：{{gift_info.three_type}}</div>
        <div>材质：{{gift_info.texture}}</div>
        <div>产品尺寸：{{gift_info.product_size}}</div>
        <div>包装尺寸：{{gift_info.packing_size}}</div>
        <div v-show="type==1">>供应商：{{gift_info.supplier_name}}</div>
        <div v-show="type==1">对接人：{{gift_info.butt_man}}</div>
        <div>上架时间：{{gift_info.on_sale_time}}</div>
      </div>
    </el-dialog>
    <el-dialog width="400px" title="添加礼品" :visible.sync="addDialog" @close="addCallOf">
      <div>
        <el-input style="width:290px;margin-right:10px" size="small" v-model="formInline.gift_id" placeholder="请输入完整的礼品编号"></el-input>
          <dj-button size="small" @search="searchClick">
            <template #default>搜索</template>
          </dj-button>
      </div>
      <div class="gift_info">
        <div class="gift_img">
          <img height="70px" :src="add_gift_info.thumb">
        </div>
        <div class="info_dialog add">
          <div>名称：{{add_gift_info.name}}</div>
          <div>零售报价：{{add_gift_info.money_sell}}</div>
          <div>礼品编号：{{add_gift_info.gift_id}}</div>
          <div>神采编号：{{add_gift_info.no_obsolete}}</div>
          <div>国标码：{{add_gift_info.gb_code}}</div>
          <div>一级类别：{{add_gift_info.first_type}}</div>
          <div>二级类别：{{add_gift_info.second_type}}</div>
          <div>三级类别：{{add_gift_info.type_name}}</div>
          <div>材质：{{add_gift_info.texture}}</div>
          <div>产品尺寸：{{add_gift_info.product_size}}</div>
          <div>包装尺寸：{{add_gift_info.packing_size}}</div>
          <div>箱规：{{add_gift_info.box_num}}</div>
          <div v-show="type==1">供应商：{{add_gift_info.from_name}}</div>
          <div v-show="type==1">总部对接人：{{add_gift_info.docking_nick}}</div>
          <div v-show="type==2">剩余库存：{{add_gift_info.num?add_gift_info.num-addGoodsNum:''}}</div>
          <div>上架时间：{{add_gift_info.on_sale_time}}</div>
          <span>使用区域：</span>
          <el-select size="mini" v-model="add_gift_info.area_type" style="width:140px" placeholder="请选择使用区域">
            <el-option v-for="item in area_list" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </div>
        <div class="gift_num">
          <div class="num_tag">数量</div>
          <el-input-number size="small" v-model="addGoodsNum" :min="1" :max="add_gift_info.num*1>999999?999999:add_gift_info.num*1"
            :step="add_gift_info.box_num*1>0?add_gift_info.box_num*1:1"></el-input-number>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button :disabled="!add_gift_info.gift_id" type="primary" size="mini" @click="addGiftToCar()">添加</el-button>
        </div>
      </div>
    </el-dialog>
    <!-- 提交订单弹出窗口 -->

    <el-dialog :visible.sync="isShowAddCart" width="1000px" title="收货信息" class="myorderDialog">
      <div style="width:100%;height:520px;font-size:18px">
        <!-- 收货信息 -->
        <div style="width:100%;height:160px">
          <div style="width:30%;height:50%;margin-right:3%;float:left">
            <div style="width:100%;height:65%">
              <span style="width:75px;display:inline-block;font-size:14px">采购渠道：</span>
              {{this.type==1?"供应商":"中央仓"}}
            </div>
            <div style="width:100%;height:50%">
              <span style="width:24%;display:inline-block;text-align:right;font-size:14px">收货人：</span>
              <el-input disabled size="small" placeholder="请输入姓名" style="width:150px" v-model="sInfo.name"></el-input>
            </div>
          </div>
          <el-form :inline="true" :model="saveForm" class="demo-form-inline" size="small">
            <el-form-item>
              <span style="font-size:14px">门店：</span>
              <el-select disabled v-model="sInfo.store_name">
                <el-option v-for="item in  house_list" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item class="myStorehouse">
              <span style="font-size:14px">收货仓：</span>
              <el-select disabled v-model="sInfo.house_name">
                <el-option v-for="item in store_list" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <div style="width:30%;height:50%;float:left;margin-right:3%;margin-left:-43px;">
            <div style="width:100%;height:50%">
              <span style="width:30%;display:inline-block;font-size:14px">收货人手机：</span>
              <el-input disabled placeholder="请输入手机号码" v-model="sInfo.phone" class="phoneInput"></el-input>
            </div>
          </div>
          <div style="width:30%;height:50%;margin-right:3%;float:left" class="myArea">
            <div style="width:388px;height:50%;display:flex;margin-left: -31px;">
              <!-- 地区 -->
              <span style="font-size:14px;text-align:right;display:inline-block;width:75px;line-height:29px;padding-right:2px">地区：</span>
              <el-form :inline="true" :model="formInline" class="demo-form-inline" size="small">
                <el-form-item>
                  <keep-alive>
                    <dj-region v-if="isShowAddCart" :prov="reg.prov" :city="reg.city" :area="reg.area" :getName="true" :disabled="true"
                      @provVal="provVal(arguments)" @cityVal="cityVal(arguments)" @areaVal="areaVal(arguments)" ref="region"></dj-region>
                  </keep-alive>
                </el-form-item>
              </el-form>
            </div>
          </div>
          <div style="width:100%;height:80px;line-height:80px;float:left;margin-top:-35px;">
            <span style="display:inline-block;height:80px;width:70px;font-size:14px">详细地址：</span>
            <el-input type="textarea" :rows="2" disabled placeholder="请输入详细地址" :maxlength="160" resize="none" v-model="sInfo.address"
              style="display:inline-block;width:860px"></el-input>
          </div>
        </div>
        <!-- 订单信息 -->
        <div style="width:935px;height:120px;display:flex;flex-direction:column;justify-content:flex-end">
          <div style="width:100%;height:50px;background:#f5f7fa;line-height:50px;font-size:16px;padding-left:10px">订单信息</div>
          <p style="text-align:center">
            种类合计：{{list.length}}种 数量合计：{{allNum}}个
            金额合计(不包含运费)：{{allTotal}}元
          </p>
        </div>
        <div style="width:100%;height:200px">
          <div style="75px;height:196px;line-height:200px;float:left;font-size:14px;border:1px solid #e4e7ed;border-right:none;height:206px">订单备注：</div>
          <div style="width:88%;height:50%;float:left">
            <template>
              <el-input type="textarea" :rows="4" placeholder="备注" resize="none" :disabled="true" v-model="remarkInfo"
                style="display:inline-block;width:862px;height:100px"></el-input>
            </template>
          </div>
          <div style="width:88%;height:50%;float:left">
            <el-input type="textarea" :rows="4" placeholder="备注" v-model="sInfo.remark" resize="none" style="display:inline-block;width:862px;height:100px"
              :maxlength="160"></el-input>
          </div>
        </div>
        <div style="width:100%;height:40px;margin-top:35px;margin-left:-27px;">
          <div style="text-align:right">
            <el-button @click="isShowAddCart= false">上一步</el-button>
            <el-button type="primary" @click="saveClick()">保存</el-button>
          </div>
        </div>
      </div>
    </el-dialog>
    <!-- 选择区域 -->
    <region-use-dialog ref="regionUseDialog" :area_type="area_type" @change_area_type="change_area_type"></region-use-dialog>
    <!-- 自定义底部 -->
    <div class="bottom_box">
      <el-button class="pull-right" size="small" type="primary" @click="receiving()" v-show="!isShowAddGift&&!isLook">修改</el-button>
      <div v-show="isShowAddGift&&!isLook" class="pull-right">
        <el-button @click="cancel" type="primary" size="small">取消</el-button>
        <el-button @click="nextStep" type="primary" size="small">下一步</el-button>
      </div>
      <div class="pull-right total">
        <span>种类合计：{{list?list.length:0}}种</span>
        <span>当前数量合计：{{allNum}}个</span>
        <span>当前金额合计(不包含运费)：{{allTotal}}元</span>
      </div>
    </div>
  </div>
</template> 
<script>
import { getList, getPage, getInfo, getDetail, getGoodsList, updateOrder } from '@/api/warehouse/detailModeify';
import { positiveInt } from '@/utils/validate';
import { getAllInfo } from '@/api/dashboard/orderIndex';
import regionUseDialog from '@/components/order/regionUseDialog';
export default {
  components: { 'region-use-dialog': regionUseDialog },
  data() {
    return {
      region: '0',
      store: '',
      isLook: false,
      house: '',
      oldData: {}, //未修改的数据
      sInfo: {},
      area_type: {},
      reg: {
        prov: '',
        city: '',
        area: ''
      },
      prov: '3',
      house_list: [],
      store_list: [],
      remarkInfo: '',
      formInline: {
        no_obsolete: '',
        name: '',
        gb_code: '',
        gift_id: '',
        from: ''
      },
      add_gift_info: {area_type:''},
      searchType: '1',
      listLoading: false,
      myinfoDialog: false,
      list: [],
      area_list: [
        { id: '1', name: '礼品机区域' },
        { id: '2', name: '礼品柜区域' },
        { id: '3', name: '摊位机区域' },
        { id: '4', name: '企划区域' },
        { id: '5', name: '其他区域' },
      ],
      top_list: [
        { name: '订货预估', a1: 0, a2: 0, a3: 0, a4: 0, a5: 0, a6: 0, a7: 0, a8: 0, a9: 0, a10: 0, a11: 0, a12: 0 },
        { name: '订货累计', a1: 0, a2: 0, a3: 0, a4: 0, a5: 0, a6: 0, a7: 0, a8: 0, a9: 0, a10: 0, a11: 0, a12: 0 }
      ],
      index_info:[
        { a1: 0, a2: 0, a3: 0, a4: 0, a5: 0, a6: 0, a7: 0, a8: 0, a9: 0, a10: 0 },
        { a1: 0, a2: 0, a3: 0, a4: 0, a5: 0, a6: 0, a7: 0, a8: 0, a9: 0, a10: 0 }      
      ], //订货指标
      currentPage: 1,
      totalDataNumber: 1,
      type: '',
      order_id: '',
      id: '',
      options: {
        //预览图配置
        toolbar: true,
        url: 'data-source'
      },
      gift_info: {},
      global: {
        store_name:"",
        store_id:"",
        starttime:"",
      },
      count: 0,
      num: 0,
      isShowAddGift: false,
      getPageParam: {
        store_id: '', //门店
        type: '', //门店下单   总部统配
        from: '', //供应商   中央仓
        order_id: '' //订单编号
      },
      addDialog: false,
      addGoodsNum: 1,
      isShowAddCart: false, //是否显示具体收货信息
      saveForm: {
        order_list: [], //购买了哪些商品
        id: '' //订单的id
      },
      route: {
        name: 'warehouse/giftDetailModify'
      }
    };
  },
  beforeRouteEnter(to, from, next) {
    next(vm => {
      //当进入组件之前，执行 beforRouteEnter 路由钩子函数 ,//参数vm就是当前组件的实例。
      if (vm.$route.params.routerflag) {
        vm.type = vm.$route.params.from;
        vm.formInline.from = vm.type;
        vm.order_id = vm.$route.params.order_id;
        vm.saveForm.id = vm.$route.params.id;
        vm.sInfo = vm.$route.params.info;
        vm.reg.prov = vm.sInfo.prov;
        vm.reg.city = vm.sInfo.city;
        vm.reg.area = vm.sInfo.dist;
        vm.saveForm.prov = vm.sInfo.prov;
        vm.saveForm.city = vm.sInfo.city;
        vm.saveForm.dist = vm.sInfo.dist;
        vm.saveForm.prov_name = vm.sInfo.prov_name;
        vm.saveForm.city_name = vm.sInfo.city_name;
        vm.saveForm.dist_name = vm.sInfo.dist_name;
        vm.global.store_name=vm.sInfo.store_name;
        vm.global.store_id=vm.sInfo.store_id;
        vm.global.starttime=vm.$route.params.time;
        vm.isLook = vm.$route.params.isLook;
        vm.isShowAddGift = false;
        vm.fatchData();
      }
    });
  },
  methods: {
    addGiftToCar() {
      if(!this.add_gift_info.area_type){
        this.$message.error("请选择使用区域");
        return ;
      }
      let index = this.list.findIndex(val => val.gift_id == this.add_gift_info.gift_id);
      if (index > -1) {
        this.list[index].now_order_num = this.list[index].now_order_num * 1 + this.addGoodsNum * 1;
        this.list[index].order_num = this.list[index].type == 1 ? this.list[index].order_num : this.list[index].now_order_num;
        this.list[index].now_num = this.add_gift_info.num * 1;
        this.list[index].area_type = this.add_gift_info.area_type;
        this.list[index].now_money_sell = (this.add_gift_info.money_sell / 1).toFixed(2);
      } else {
        let obj = {};
        obj.thumb = this.add_gift_info.thumb;
        obj.img = this.add_gift_info.img;
        obj.gift_name = this.add_gift_info.name;
        obj.gift_id = this.add_gift_info.gift_id;
        obj.money_sell = (this.add_gift_info.money_sell / 1).toFixed(2);
        obj.now_money_sell = (this.add_gift_info.money_sell / 1).toFixed(2);
        obj.now_num = this.add_gift_info.num;
        obj.box_num = this.add_gift_info.box_num;
        obj.area_type = this.add_gift_info.area_type;
        obj.order_num = this.addGoodsNum;
        obj.now_order_num = this.addGoodsNum;
        obj.isSave = true;
        this.list.unshift(obj);
      }
      this.addDialog = false;
    },
    //使用区域弹窗
    showAreaDiag(row){
      this.area_type=row;
      this.$refs.regionUseDialog.show();      
    },
    addClick() {
      this.addDialog = true;
    },
    //搜索
    searchClick() {
      this.add_gift_info = {area_type:''};
      this.addGoodsNum = 1;
      if (!this.formInline.gift_id) {
        this.$message.error('请输入礼品编号');
        return;
      }
      getGoodsList(this.formInline).then(res => {
        if (res.length != 0) {
          let data = res[0];
          data.area_type="";
          data.texture = data.texture == 'null' ? '' : data.texture;
          data.money_sell = (data.money_sell / 1).toFixed(2);
          this.add_gift_info = data;
          this.addGoodsNum = data.num * 1 < data.box_num * 1 ? data.num : data.box_num * 1 > 0 ? data.box_num : 1;
        } else {
          let text = this.type == 2 ? '未搜索到该礼品或该礼品库存不足' : '未搜索到该礼品';
          this.$message.error(text);
        }
      });
    },
    getData(data) {
      data.forEach(val => {
        val.type = 1;
        val.before_num = val.now_order_num;
        val.money_sell = (val.money_sell / 100).toFixed(2);
        val.now_money_sell = (val.now_money_sell / 100).toFixed(2);
        val.isSave = false;
      });
      this.oldData = JSON.parse(JSON.stringify(data));
      this.list = data;
    },
    getIndexData(data,type1,type2){
      let money = 0,
        num = 0;
      let list = this.list.filter(val => val.area_type == data.area_type);
      list.forEach(val => {
        num += val.now_order_num / 1;
        money += val.now_money_sell * val.now_order_num;
      });
      this.index_info[0][type1]=(data.booking_money/1000000).toFixed(2);
      this.index_info[1][type1]=(data.cumulative_money/1000000-money).toFixed(2);
      this.index_info[0][type2]=data.booking_num;
      this.index_info[1][type2]=data.cumulative_num-num;
      // this.top_list[0][type1]=this.index_info[0][type1];
      // this.top_list[1][type1]=this.index_info[1][type1];
      // this.top_list[0][type2]=this.index_info[0][type2];
      // this.top_list[1][type2]=this.index_info[1][type2];
      // this.top_list[0].a11=this.top_list[0].a11/1+this.top_list[0][type1]/1;
      // this.top_list[1].a11=this.top_list[1].a11/1+this.top_list[1][type1]/1;
      // this.top_list[0].a12=this.top_list[0].a12/1+this.top_list[0][type2]/1;
      // this.top_list[1].a12=this.top_list[1].a12/1+this.top_list[1][type2]/1;
      // this.top_list[0].a11=(this.top_list[0].a1/1+this.top_list[0].a3/1+this.top_list[0].a5/1+this.top_list[0].a7/1+this.top_list[0].a9/1).toFixed(2);
      // this.top_list[0].a12=this.top_list[0].a2/1+this.top_list[0].a4/1+this.top_list[0].a6/1+this.top_list[0].a8/1+this.top_list[0].a10/1;
    },
    //列表数据变化后重新计算累计订货指标
    getTopData(id,type1,type2){
      let list=this.list.filter(val=>val.area_type==id);
      let money=0,num=0;
      list.length&&list.forEach(val=>{
        num+=val.now_order_num/1;
        money+=val.now_order_num*val.now_money_sell;
      })
      this.top_list[1][type1]=(this.index_info[1][type1]/1+money).toFixed(2);
      this.top_list[1][type2]=this.index_info[1][type2]/1+num;
    },
    changeList(){
      this.index_info.forEach((val,i)=>{
        Object.keys(val).forEach(key => {
          this.top_list[i][key]=val[key];
        });
      })
      this.list.length&&this.area_list.forEach(val=>{
        switch (val.id/1) {
          case 1:
            this.getTopData(1,"a1","a2");
            break;
          case 2:
            this.getTopData(2,"a3","a4");
            break;
          case 3:
            this.getTopData(3,"a5","a6");
            break;
          case 4:
            this.getTopData(4,"a7","a8");
            break;
          case 5:
            this.getTopData(5,"a9","a10");
            break;       
          default:
            break;
        }
      })
      this.top_list[0].a11=(this.top_list[0].a1/1+this.top_list[0].a3/1+this.top_list[0].a5/1+this.top_list[0].a7/1+this.top_list[0].a9/1).toFixed(2);
      this.top_list[0].a12=this.top_list[0].a2/1+this.top_list[0].a4/1+this.top_list[0].a6/1+this.top_list[0].a8/1+this.top_list[0].a10/1;
      this.top_list[1].a11=(this.top_list[1].a1/1+this.top_list[1].a3/1+this.top_list[1].a5/1+this.top_list[1].a7/1+this.top_list[1].a9/1).toFixed(2);
      this.top_list[1].a12=this.top_list[1].a2/1+this.top_list[1].a4/1+this.top_list[1].a6/1+this.top_list[1].a8/1+this.top_list[1].a10/1;
    },
    change_area_type(area_type, row){
      row.area_type=area_type;
      this.changeList();
    },
    fatchData() {
      this.listLoading = true;
      getDetail({ order_id: this.saveForm.id }).then(res => {
        this.getData(res);
        getAllInfo({store_id:this.sInfo.store_id,start_time:this.global.starttime}).then(res=>{
          if(res.code==1){
            res.data.forEach(val=>{
              val.booking_num=Math.ceil(val.booking_num/1);
              switch (val.area_type/1) {
                case 1:
                  this.getIndexData(val,"a1","a2");
                  break;
                case 2:
                  this.getIndexData(val,"a3","a4");
                  break;
                case 3:
                  this.getIndexData(val,"a5","a6");
                  break;
                case 4:
                  this.getIndexData(val,"a7","a8");
                  break;
                case 5:
                  this.getIndexData(val,"a9","a10");
                  break;
                default:
                  break;
              }
            })
            this.changeList();
          }
        })
        this.listLoading = false;
      });
    },
    inputBurl(row) {
      if (!positiveInt(row.now_order_num)) {
        row.now_order_num = 1;
      } else if (row.now_order_num > row.now_num * 1 + (row.before_num ? row.before_num * 1 : 0)) {
        row.now_order_num = row.now_num * 1 + (row.before_num ? row.before_num * 1 : 0);
      }
    },
    receiving() {
      //修改
      this.isShowAddGift = true;
      this.list.forEach(val => {
        val.isSave = true;
      });
    },
    getRegion() {
      this.$router.push({
        name: 'operation/category_order_indicator',
        params: {
          row:{},
          global: this.global,
          routerflag: true
        }
      });
    },
    cancel() {
      this.isShowAddGift = false;
      this.list = JSON.parse(JSON.stringify(this.oldData));
      this.changeList();
    },
    //新增礼品弹窗重置
    addCallOf() {
      this.add_gift_info = {};
      this.addGoodsNum = 1;
      this.formInline.gift_id = '';
    },
    nextStep() {
      if (this.list.length == 0) {
        this.$message.error('请选择礼品!');
        return;
      }
      let isPass = true;
      let remarkInfo = '';
      let notAreaId="";
      this.list.forEach(val => {
        if(!val.area_type||val.area_type==0){
          notAreaId+=val.gift_id+',';
        }
      });
      if(notAreaId){
        // notAreaId=notAreaId.substr(0, notAreaId.length - 1);
        this.$message.error(`${notAreaId}礼品未选择礼品区域,请先选择礼品区域!`);
        return;        
      }
      for(let val of this.list){
        if (!positiveInt(val.now_order_num)) {
          this.$message.error('礼品数量只能为正整数');
          isPass = false;
          break;
        } else if (this.type == 2 && val.now_order_num * 1 > val.now_num * 1 + (val.before_num ? val.before_num * 1 : 0)) {
          this.$message.error('礼品数量不能大于剩余库存');
          isPass = false;
          break;
        }
        if (val.remark) {
          remarkInfo += '【' + val.gift_id + '#' + val.gift_name + '】' + val.remark + ';';
        }
      }
      if (!isPass) {
        return;
      }
      this.remarkInfo = remarkInfo;
      this.isShowAddCart = true;
    },
    operNum(type, row) {
      if (type == 0) {
        // 删除
        if (row.now_order_num == 0) {
          return;
        }
        row.now_order_num--;
      } else if (type == 1) {
        //添加
        row.now_order_num++;
      }
    },
    saveClick() {
      if (!this.sInfo.name) {
        this.$message.error('收货人不能为空!');
        return;
      }
      if (!this.sInfo.phone) {
        this.$message.error('手机号不能为空!');
        return;
      }

      if (!this.reg.prov || !this.reg.city) {
        this.$message.error('请选择详细地址!');
        return;
      }
      let nameReg = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/; //验证姓名正则
      if (!nameReg.test(this.sInfo.name)) {
        this.$message.error('输入名字不规范');
        return;
      }
      let phoneReg = /^1[3-9]\d{9}$/;
      if (!phoneReg.test(this.sInfo.phone)) {
        this.$message.error('电话号码格式不正确');
        return;
      }
      this.errNum = '';
      this.saveForm.order_list = [];
      this.list.forEach(val => {
        let obj = {
          total_num: val.now_order_num ? val.now_order_num : val.total_num,
          gift_id: val.gift_id,
          type: this.type,
          look_money: val.money_sell,
          area_type: val.area_type,
          remark: val.remark
        };
        this.saveForm.order_list.push(obj);
      });
      this.saveForm.name = this.sInfo.name;
      this.saveForm.phone = this.sInfo.phone;
      this.saveForm.type = this.type;
      this.saveForm.house_id = this.sInfo.house_id;
      this.saveForm.store_id = this.sInfo.store_id;
      this.saveForm.remark = this.sInfo.remark;
      this.saveForm.address = this.sInfo.address;
      updateOrder(this.saveForm).then(res => {
        if (res.code == 1) {
          this.$message.success(res.message);
          this.isShowAddCart = false;
          this.saveForm = { order_list: [], id: '' };
          this.$store.dispatch('delVisitedViews', this.route).then(() => {
            this.isShowAddCart = false;
            this.$router.push({
              name: 'warehouse/detailModify',
              params: { update: 1 }
            });
          });
        }
      });
    },
    // 子组件传过来的省
    provVal(val) {
      this.saveForm.prov = val[0];
      this.saveForm.prov_name = val[1];
    },
    // 子组件传过来的市
    cityVal(val) {
      this.saveForm.city = val[0];
      this.saveForm.city_name = val[1];
    },
    // 子组件传过来的区
    areaVal(val) {
      this.saveForm.dist = val[0];
      this.saveForm.dist_name = val[1];
    },
    handleClick(index) {
      this.$confirm('确定要删除该商品吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.list.splice(index, 1);
      });
    }
  },
  watch:{
    allTotal:function(val){
      this.changeList();
    }
  },
  computed: {
    allNum: function() {
      if (this.list.length <= 0) {
        return 0;
      }
      let num = 0;
      this.list.forEach(val => {
        num = num + val.now_order_num * 1;
      });
      return num;
    },
    allTotal: function() {
      if (this.list.length <= 0) {
        return 0;
      }
      let total = 0;
      this.list.forEach(val => {
        total = total + val.now_order_num * val.now_money_sell;
      });
      return total.toFixed(2);
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.info_dialog {
  div + div {
    margin-top: 10px;
  }
}
.gift_num {
  display: flex;
  margin-top: 10px;
  align-items: center;
  .num_tag {
    margin-right: 80px;
  }
}
.gift_img {
  height: 90px;
  text-align: center;
  padding: 10px;
}
.bottom_box {
  .total {
    margin: 8px;
    span {
      margin-right: 20px;
    }
  }
}
.dialog-footer {
  text-align: right;
}
</style>
<style scoped>
.app-container >>> .mycard.el-input > input {
  height: 28px;
}
.mycard .el-input-number span {
  line-height: 28px;
}
.app-container >>> .el-dialog .myStorehouse input {
  width: 300px;
}
.app-container >>> .el-dialog div.phoneInput {
  display: inline-block;
  width: 10px;
}
.app-container >>> .el-dialog div.phoneInput > input {
  width: 199px !important;
  height: 32px !important;
}
/* .app-container
  >>> .el-dialog
  .el-dialog__body
  .myArea
  form
  div.el-form-item__content
  > div {
  width: 300px;
}
.app-container >>> .el-dialog .el-dialog__body .myArea > div {
  width: 500px;
  display: flex;
}
.app-container >>> .el-dialog .el-dialog__body .myArea form > div {
  margin-left: 0;
} */
.app-container >>> .myorderDialog .el-dialog {
  height: 680px;
}
.app-container >>> .el-dialog textarea {
  border-radius: unset;
  padding: 10px 15px;
}
</style>
